from jose import JWTError, jwt

SECRET_KEY = "xwyzsn"
ALGORITHM = "HS256"

def create_token(data: dict):
    encoded_jwt = jwt.encode(data, SECRET_KEY, algorithm=ALGORITHM)
    return encoded_jwt

def decode_token(token: str):
    try:
        payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
        return payload
    except JWTError:
        raise JWTError


if __name__ == "__main__":
    token = create_token({"username":"xwyzsn","password":"123456","role":"admin"})
    print(token)
    token = token.replace("e","a")
    print(decode_token(token))